<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/1/6
 * Time: 10:09
 */

require '../vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Processor\IntrospectionProcessor;
// Build a Monolog logger that uses the SyslogHandler

$logger    = new Logger('log');
$handler   = new SyslogHandler('my_user');
$processor = new IntrospectionProcessor();

$logger->pushHandler($handler);
$logger->pushProcessor($processor);

$params['logging'] = true;
//$params['logObject'] = $logger;
$params['logPath'] = __DIR__.'/elasticsearch.log';
$params['logLevel'] = Psr\Log\LogLevel::INFO;
$params['logPermission'] = 0664;

$params['hosts'] = array (
	'192.168.51.124:9200',                 // IP + Port
//	'192.168.1.2',                      // Just IP
//	'mydomain.server.com:9201',         // Domain + Port
//	'mydomain2.server.com',             // Just Domain
//	'https://localhost',                // SSL to localhost
//	'https://192.168.1.3:9200',         // SSL to IP + Port
//	'http://user:pass@localhost:9200',  // HTTP Basic Auth
//	'https://user:pass@localhost:9200',  // SSL + HTTP Basic Auth
);
$client = new Elasticsearch\Client($params);
$result = $client->get( [ 'index' => 'megacorp', 'type' => 'employee','id' => 1 ] );
var_dump($result);
$params = array(
	'index'  => 'megacorp',
	'type'   => 'employee',
	'id'     => 11,
	'ignore' => 404
);
echo $client->get($params).PHP_EOL;

$getParams = array(
	'index' => 'megacorp',
	'type' => 'employee',
	'id' => 1,
//	'parent' => 'abc',  // white-listed
//	'custom' => array('customToken' => 'abc', 'otherToken' => 123) // user-defined, not white listed, not checked
);
$exists = $client->exists($getParams);
var_dump($exists);


//Default Configurations.
//$paramDefaults = array(
//	'connectionClass'       => '\Elasticsearch\Connections\GuzzleConnection',
//	'connectionFactoryClass'=> '\Elasticsearch\Connections\ConnectionFactory',
//	'connectionPoolClass'   => '\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool',
//	'selectorClass'         => '\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector',
//	'serializerClass'       => '\Elasticsearch\Serializers\SmartSerializer',
//	'sniffOnStart'          => false,
//	'connectionParams'      => array(),
//	'logging'               => false,
//	'logObject'             => null,
//	'logPath'               => 'elasticsearch.log',
//	'logLevel'              => Log\LogLevel::WARNING,
//	'traceObject'           => null,
//	'tracePath'             => 'elasticsearch.log',
//	'traceLevel'            => Log\LogLevel::WARNING,
//	'guzzleOptions'         => array(),
//	'connectionPoolParams'  => array(
//		'randomizeHosts' => true
//	),
//	'retries'               => null
//);